package src.multithreading;
//模拟网络延迟
//模拟网络延迟可以起到放大问题的发生性
public class TestSleep implements Runnable{
    private int pingNetwork = 3;
    private boolean flag = true;
    @Override
    public void run() {
        while(flag) {
            if (pingNetwork > 0) {
                pingNetwork(pingNetwork);
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            } else {
                stop();
            }
        }




    }
    public void pingNetwork(int pingNetwork){
        System.out.println("ping"+pingNetwork+"次，网络连接0延迟");
        this.pingNetwork--;
    }
    public void stop(){
        this.flag = false;
    }

    public static void main(String[] args) {
        TestSleep testSleep =new TestSleep();
        new Thread(testSleep).start();
    }
}
